home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / bplus11.zip / FILELEN.C < prev    next >
C/C++ Source or Header  |  1988-12-07  |  663b  |  26 lines

  1. /*****************************************************************
  2.  |  filelength - returns the length of a file
  3.  ****************************************************************/
  4.  
  5. long  filelength (fd)
  6.     int  fd;
  7. {
  8. #if    0        /* original version */
  9.     long  orig, last, lseek();
  10.  
  11.     orig = lseek (fd, 0L, 1);        /* seek to the current position */
  12.     last = lseek (fd, 0L, 2);        /* seek to the end */
  13.     lseek (fd, orig, 0);        /* reset the pointer */
  14.  
  15.     return last;
  16. #else            /* new network version */
  17. #include <fcntl.h>
  18. #include <sys/types.h>
  19. #include <sys/stat.h>
  20.  
  21.     struct stat sb;
  22.     fstat(fd, &sb);
  23.     return sb.st_size;
  24. #endif
  25. }
  26.